

import 'package:bt_tool/basic/bt_controller.dart';
import 'package:bt_tool/basic/bt_language_tool.dart';
import 'package:bt_tool/basic/bt_nav_tool.dart';
import 'package:bt_tool/basic/bt_utils.dart';
import 'package:bt_tool/widget/bt_base_btn_widget.dart';
import 'package:bt_tool/widget/bt_form_select_widget.dart';
import 'package:bt_tool/widget/bt_text_field.dart';
import 'package:bt_tool/widget/bt_widget.dart';
import 'package:bt_tool/widget/pcList/bt_pc_list_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/tools/translate/controller/translate_main_controller.dart';
import 'package:flutter_demo/tools/translate/page/translate_main_head_widgtet.dart';
import 'package:flutter_demo/tools/translate/page/translate_main_item_widget.dart';
import 'package:get/get.dart';

import '../../../common/config/app_theme_color_config.dart';
import '../model/translate_content_model.dart';

class TranslateMainPage extends BTStatefulWidget{
  const TranslateMainPage({super.key,super.routerConfig});

  @override
  State<StatefulWidget> createState() {
    return TransLateMainState();
  }

}

class TransLateMainState extends BTState<TranslateMainPage>{

  final TranslateMainController controller = TranslateMainController();

  @override
  BTController btCtrl() {
    return controller;
  }

  @override
  Widget build(BuildContext context) {
    Widget contentWidget;
    if(btIsStrEmpty(controller.projectModel?.translateConfig)){
      contentWidget = Align(
        alignment: Alignment.center,
        child: GestureDetector(
          onTap: ()=>controller.configClick(),
          child: const Text("暂无配置翻译语言，点击前往配置"),
        ),
      );
    }else{
      contentWidget = Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: BTPcListWidget(
              pcController: controller.pcListController,
              headModelList: controller.headModelList,
              itemHeight: 100,
              topContentWidget: TranslateMainHeadToolWidget(controller: controller),
              topContentHeight: 50,
              itemBuilder: (context,index,height,totalWidth){
                return TranslateMainItemWidget(
                    isHead: false,
                    model: controller.dataList[index],
                    mainController: controller
                );
              },
            ),
          ),
          const SizedBox(height: 10,),
          bottomActionWidget(),
        ],
      );


    }

    return Scaffold(
      appBar: BTNavTool.createAppBar(
        title: "翻译(${controller.projectModel?.name})",
        context: context,
        actionListStr: ["设置"],
        rightPadding: 10,
        actionCallBack: (index)=>controller.configClick(),
      ),
      body: Container(
        padding: const EdgeInsets.all(12),
        child: contentWidget,
      ),
    );
  }

  Widget bottomActionWidget(){
    return Row(
      children: [
        BTBtnTextWidget(
          bgColor: AppThemeColor.mainColor,
          text: "新增",
          textColor: Colors.white,
          onTap: () => controller.createClick(),
          alignment: Alignment.center,
        ),
        const SizedBox(width: 10,),
        BTBtnTextWidget(
          bgColor: AppThemeColor.mainColor,
          text: "翻译数据",
          textColor: Colors.white,
          onTap: () => controller.translateClick(),
          alignment: Alignment.center,
        ),
        const SizedBox(width: 10,),
        BTBtnTextWidget(
          bgColor: AppThemeColor.mainColor,
          text: "导出数据",
          textColor: Colors.white,
          onTap: () => controller.exportSelectData(),
          alignment: Alignment.center,
        ),
        const SizedBox(width: 10,),
        BTBtnTextWidget(
          bgColor: AppThemeColor.mainColor,
          text: "设置为已导出",
          textColor: Colors.white,
          onTap: () => controller.setSelectDataToDidExport(),
          alignment: Alignment.center,
        ),
        Expanded(
          child: Align(
            alignment: Alignment.centerRight,
            child: Obx(()=>Text("共计${controller.totalDataNum.value}条数据")),
          ),
        )
      ],
    );
  }

}